package drds.global_transaction;

import java.security.MessageDigest;


public class Md5
{
    public static String md5(String string)
    {
        try
        {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] bytes = messageDigest.digest(string.getBytes("utf-8"));
            return toHex(bytes);
        } catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }

    public static String toHex(byte[] bytes)
    {

        final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++)
        {
            sb.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]);
            sb.append(HEX_DIGITS[bytes[i] & 0x0f]);
        }
        return sb.toString();
    }
}
